﻿using MengLin.OOP.DesignPattern.Implement.MySql;
using MengLin.OOP.DesignPattern.Implement.Orcal;
using MengLin.OOP.DesignPattern.Implement.SqlServer;
using MengLin.OOP.DesignPattern.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.SimpleFactory
{
    /// <summary>
    /// 封装转移
    /// 把对象的创建交给第三方创建
    /// 简单工厂模式：包含一组一类需要创建的对象，通过一个工厂类来实例化对象
    /// 缺点是
    /// 1.没有消除依赖，只是转移依赖，到是把依赖集中了
    /// 2.违背了单一职责原则，职责太多，1个类干了太多事(new这个，new那个)
    /// </summary>
    public class ObjFactory
    {
        /// <summary>
        /// 创建实例
        /// </summary>
        /// <param name="dbType"></param>
        /// <returns></returns>
        public static IUserService CreateInstance(DbType dbType)
        {
            IUserService iUserService = null;
            switch (dbType)
            {
                case DbType.Orcal:
                    iUserService = new OrcalUserService();
                    break;
                case DbType.SqlServer:
                    iUserService = new SqlServerUserService();
                    break;
                //case DbType.MySql://注意：这里是编辑
                //    iUserService = new MySqlUserService();
                //    break;
                default:
                    break;
            }
            return iUserService;
        }
    }

    /// <summary>
    /// 数据库类型枚举
    /// </summary>
    public enum DbType
    {
        Orcal = 0,
        SqlServer = 1,
        MySql = 2
    }
}
